import random

import requests
import re


# 1. User-Agent

# url = "http://127.0.0.1:8000/useragent/"

# # 使用headers
# headers = {'User-Agent': '1111111111'}

# # 使用UA池
# uas = ['111111', '2222222', '33333333']
# headers = {'User-Agent': random.choice(uas)}

# # 使用fake-useragent
# from fake_useragent import UserAgent
# ua = UserAgent()
# print(ua.random)
# headers = {'User-Agent': ua.random}

# response = requests.get(url, headers=headers)
# if response.status_code == 200:
#     print(response.text)

# 2. cookies

# url = "http://127.0.0.1:8000/cookie/"

# # header添加cookie
# header = {
#     # 'cookie':'csrftoken=gkaNa2QiJjkw6pyjkwFBFLulT3HHLlDm; sessionid=zd686wfcoeadyvp6e8ksaa0xq1lrv2ml'
# }

# # 设置cookies
# cookies = {
#     'sessionid':'zd686wfcoeadyvp6e8ksaa0xq1lrv2ml'
# }

# response = requests.get(url, headers=header, cookies=cookies)
# if response.status_code == 200:
#     print(response.text)


# 3. referer

url = "http://127.0.0.1:8000/referer/"

headers = {
    'Referer':'http://127.0.0.1:8000/'
}

response = requests.get(url, headers=headers)
if response.status_code == 200:
    print(response.text)